package com.tdkj.service.home.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.tdkj.dao.friendlylink.IBeanFriendlylinkDao;
import com.tdkj.dao.information.IBeanBaseInfoDao;
import com.tdkj.dao.information.IBeanExpertDao;
import com.tdkj.dao.selfadvert.IBeanSelfAdvertDao;
import com.tdkj.dao.website.IBeanWebsiteNoticeDao;
import com.tdkj.dao.yellowpage.IBeanEnterpriceDao;
import com.tdkj.model.base.BaseEntity;
import com.tdkj.model.common.BeanType;
import com.tdkj.model.friendlylink.BeanFriendlylink;
import com.tdkj.model.information.BeanBaseInfo;
import com.tdkj.model.information.BeanExpert;
import com.tdkj.model.selfadvert.BeanSelfAdvert;
import com.tdkj.model.shop.BeanGood;
import com.tdkj.model.website.BeanWebsiteNotice;
import com.tdkj.model.yellowpage.BeanEnterprice;
import com.tdkj.service.BaseService;
import com.tdkj.service.home.IBeanHomePageService;
import com.tdkj.util.Page;
@Component("homePageService")
public class BeanHomePageImpl extends BaseService implements IBeanHomePageService{
	private IBeanBaseInfoDao infoDao;
	private IBeanEnterpriceDao enterpriceDao;
	private IBeanExpertDao expertDao;
	private IBeanFriendlylinkDao friendlinkDap;
	private IBeanWebsiteNoticeDao noticeDao;
	private IBeanSelfAdvertDao selfAdvertDao;
	
	public IBeanSelfAdvertDao getSelfAdvertDao() {
		return selfAdvertDao;
	}
	@Resource
	public void setSelfAdvertDao(IBeanSelfAdvertDao selfAdvertDao) {
		this.selfAdvertDao = selfAdvertDao;
	}
	public IBeanBaseInfoDao getInfoDao() {
		return infoDao;
	}
	@Resource
	public void setInfoDao(IBeanBaseInfoDao infoDao) {
		this.infoDao = infoDao;
	}

	public IBeanEnterpriceDao getEnterpriceDao() {
		return enterpriceDao;
	}
	@Resource
	public void setEnterpriceDao(IBeanEnterpriceDao enterpriceDao) {
		this.enterpriceDao = enterpriceDao;
	}
	public IBeanExpertDao getExpertDao() {
		return expertDao;
	}
	@Resource
	public void setExpertDao(IBeanExpertDao expertDao) {
		this.expertDao = expertDao;
	}
	public IBeanFriendlylinkDao getFriendlinkDap() {
		return friendlinkDap;
	}
	@Resource
	public void setFriendlinkDap(IBeanFriendlylinkDao friendlinkDap) {
		this.friendlinkDap = friendlinkDap;
	}
	public IBeanWebsiteNoticeDao getNoticeDao() {
		return noticeDao;
	}
	@Resource
	public void setNoticeDao(IBeanWebsiteNoticeDao noticeDao) {
		this.noticeDao = noticeDao;
	}
	@Override
	public List<BeanEnterprice> findEnterprices() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanEnterprice.class);
		criteria.addOrder(Order.desc("enterpricename"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public List<BeanExpert> findExperts() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanExpert.class);
		criteria.addOrder(Order.desc("expertname"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public List<BeanBaseInfo> findHarbors() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "10"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public List<BeanBaseInfo> findInvests() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "4"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public List<BeanBaseInfo> findMerchants() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "5"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public List<BeanBaseInfo> findMineKnowledges() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "13"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public Map<String, List<BeanBaseInfo>> findMiningrights() {
		// TODO Auto-generated method stub
		Map<String, List<BeanBaseInfo>> m=new HashMap<String, List<BeanBaseInfo>>();
		List<BeanBaseInfo> l=null;
		BeanBaseInfo bean=null;
		for(int i=1;i<7;i++){
			Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
			criteria.add(Restrictions.eq("moduletype", "7"));
			criteria.add(Restrictions.eq("columntype", i+""));
			criteria.addOrder(Order.desc("createtime"));
			l=this.getBaseDao().findBy(criteria, 1, 10).getList();
			m.put(i+"", l);
		}
		return m;
	}

	@Override
	public List<BeanBaseInfo> findPolicys() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "12"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public List<BeanBaseInfo> findProspects() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "8"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}

	@Override
	public Map<String, List<BeanBaseInfo>> findRecruits() {
		Map<String, List<BeanBaseInfo>> m=new HashMap<String, List<BeanBaseInfo>>();
		List<BeanBaseInfo> l=null;
		BeanBaseInfo bean=null;
		for(int i=1;i<6;i++){
			l=new ArrayList<BeanBaseInfo>();
			Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
			criteria.add(Restrictions.eq("moduletype", "9"));
			criteria.add(Restrictions.eq("columntype", i+""));
			criteria.addOrder(Order.desc("createtime"));
			l=this.getBaseDao().findBy(criteria, 1, 10).getList();
			m.put(i+"", l);
		}
		return m;
	}

	@Override
	public List<BeanBaseInfo> findTrades() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "1"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 20).getList();
	}

	@Override
	public Map<String, List<BeanBaseInfo>> findProductPrices() {
		Map<String, List<BeanBaseInfo>> m=new HashMap<String, List<BeanBaseInfo>>();
		List<BeanBaseInfo> l=null;
		BeanBaseInfo bean=null;
		for(int i=3;i<5;i++){
			l=new ArrayList<BeanBaseInfo>();
			Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
			criteria.add(Restrictions.eq("moduletype", "3"));
			criteria.add(Restrictions.eq("columntype", i+""));
			criteria.addOrder(Order.desc("createtime"));
			l=this.getBaseDao().findBy(criteria, 1, 10).getList();
			m.put(i+"", l);
		}
		return m;
	}
	@Override
	public List<BeanFriendlylink> findFriendlinks() {
		// TODO Auto-generated method stub
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanFriendlylink.class);
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}
	@Override
	public List<BeanBaseInfo> findQuotationGuides() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("moduletype", "3"));
		criteria.add(Restrictions.eq("columntype", "2"));
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}
	@Override
	public List<BeanSelfAdvert> findSelfAdverts() {
		// TODO Auto-generated method stub
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanSelfAdvert.class);
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}
	/*
	 * (non-Javadoc)
	 * @see com.tdkj.service.home.IBeanHomePageService#findRecommendtionGoods()
	 * 获取商品推荐
	 */
	@Override
	public List<BeanGood> findRecommendtionGoods() {
		String hql = " select bean from " + BeanGood.class.getName() + " as bean where bean.sellType='1' order by publishTime desc";
		Query queryAuction = this.getBaseDao().getSession().createQuery(hql);
		Page auctionGoods = this.getBaseDao().findBy(queryAuction, 1, 20);
		return auctionGoods.getList();
	}
	@Override
	public List<BeanType> findGoodTypes() {
		String hql = " from " + BeanType.class.getName() + " as bean where bean.rootName='GOOD_ROOT' and level='1'";
		Query queryAuction = this.getBaseDao().getSession().createQuery(hql);
		Page goodTypes = this.getBaseDao().findBy(queryAuction, 1, 20);
		return goodTypes.getList();
	}
	@Override
	public List<BeanGood> findGoods() {
		String hql = " from " + BeanGood.class.getName() + " as bean order by bean.publishTime desc";
		Query queryAuction = this.getBaseDao().getSession().createQuery(hql);
		Page goods = this.getBaseDao().findBy(queryAuction, 1, 20);
		return goods.getList();
	}
	@Override
	public List<BeanWebsiteNotice> findWebsiteNotices() {
		Criteria criteria=this.getBaseDao().getSession().createCriteria(BeanWebsiteNotice.class);
		criteria.addOrder(Order.desc("createtime"));
		return this.getBaseDao().findBy(criteria, 1, 10).getList();
	}
}
